﻿using MediatR;
using Traceability.App.Api.Read.Application.Command.Fram;
using Traceability.App.Domain.养殖基本信息表;
using Traceability.App.Domain.新文件夹;
using Traceability.App.ErrorCode;
using Traceability.App.Intrastructure.Interface;

namespace Traceability.App.Api.Read.Application.Handler.Fram
{
    public class FramHandler : IRequestHandler<FramCommand, ApiResult<FarmModel>>
    {
        private readonly IBaseRepository<FarmModel> farmRepo;

        public FramHandler(IBaseRepository<FarmModel> farmRepo)
        {
            this.farmRepo = farmRepo;
        }
        public Task<ApiResult<FarmModel>> Handle(FramCommand request, CancellationToken cancellationToken)
        {
            var res = new ApiResult<FarmModel>();
            var m = farmRepo.GetAll().FirstOrDefault(x => x.ProduceBatch == request.ProduceBatch);
            res.Message = "养殖详情显示成功";
            res.Code = ApiEnum.Ok;
            res.Data = m;
            return Task.FromResult(res);
        }
    }
}
